/**
 * Created by oysmlsy on 2017/2/10.
 */
CKEDITOR.plugins.add('custom_link_file', {
    init: function (editor) {
        editor.ui.addButton('custom_link_file', {
            label: '链接文件',
            command: 'custom_link_file',
            icon: this.path + 'images/icon.png',
            click: function () {
                var selectedText = editor.getSelection().getSelectedText();
                if(selectedText != ''){
                    if(editor.getSelection().getStartElement().getName() != "a"){
                        var insertedHtml = '<a href="{{链接文件}}" target="_blank">' + selectedText + "</a>";
                        editor.insertHtml(insertedHtml);
                    }else{
                        var insertedHtml = editor.getSelection().getStartElement().getHtml()
                        editor.getSelection().getStartElement().remove()
                        editor.insertText(insertedHtml);
                    }
                }
            }
        });
    }
});